function [Q] = csg2(A)
 
% 初始化一个与A相同维度的零矩阵Q
[m, n] = size(A);
Q = zeros(m, n);

% 初始化一个与A相同维度的零矩阵R
R = zeros(n, n);

for j = 1:n
    v = A(:, j);
    for i = 1:j-1
        R(i, j) = Q(:, i)' * A(:, j);
        v = v - R(i, j) * Q(:, i);
    end
    R(j, j) = norm(v);
    Q(:, j) = v / R(j, j);
end

% 删除接近零的列
tolerance = 1e-10; % 设置一个容忍的阈值，根据需要调整
norms = sqrt(sum(Q.^2));
nonzero_columns = norms > tolerance;
Q = Q(:, nonzero_columns);

